home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2006 May / PCWMAY06.iso / Software / Freeware / First Page 2006 3.00 / fp2006-final-3.00-setup.exe / {app} / Iscripts / Forms Misc / submit-once-frontpage.izs < prev    next >
Text File  |  2005-09-28  |  7KB  |  241 lines

  1. <!NOWIZARD>
  2.  
  3. <!TITLE>Submit Once for FrontPage 
  4.  
  5. <!/TITLE>
  6.  
  7. <!DESCRIPTION>A script that only allows the user to submit a form once. Compatible with Microsoft FrontPage's built-in validation methods, which other 'Submit Once' scripts are not. It spoofs FrontPage by dynamically re-writing the onSubmit handler in the user's browser.  <!/DESCRIPTION> 
  8.  
  9. <!CATEGORY>Forms<!/CATEGORY>
  10.  
  11. <!SCRIPT>
  12. <!-- START OF SCRIPT -->
  13.  
  14. <!-- HOW TO INSTALL SUBMIT ONCE FOR FRONTPAGE:
  15.  
  16.   1.  Copy code into the HEAD section of document
  17.   2.  Add the onLoad event handler into the BODY tag  -->
  18.  
  19. <!-- STEP ONE: Add code into HEAD section of document  -->
  20.  
  21. <HEAD>
  22.  
  23. <SCRIPT LANGUAGE="JavaScript">
  24.  
  25.  
  26. <!-- Begin
  27. function hijackValidator() {
  28.   // loop through all the Forms in the document
  29.   for (i=0; i<document.forms.length; i++) {
  30.  
  31. /* create a new property of the Form that tracks whether the Form has been submitted*/
  32.  
  33.    document.forms[i].notSubmittedYet = true;
  34.    if (document.forms[i].onsubmit) {
  35.     var oldHandler = new String(document.forms[i].onsubmit)
  36.  
  37. /*  oldHandler will be something like this, depending on the browser in use,
  38. *   and the name of the Form:
  39. *
  40. *   "function anonymous() { return FrontPage_Form1_Validator(this); }"
  41. *
  42. *   We need to extract just the "FrontPage_Form1_Validator(this)" part
  43. */
  44.  
  45.     //find "Validator"
  46.     var validatorIndex = oldHandler.indexOf("Validator");
  47.  
  48.     //if "Validator" not found, then abort
  49.     if (validatorIndex<0) return;
  50.  
  51.     //find space before name of validator function
  52.     var startIndex = oldHandler.lastIndexOf(" ",validatorIndex)
  53.  
  54.     // if space not found, abort
  55.     if (startIndex<0) return;
  56.  
  57.     // find final parenthesis
  58.     var endIndex = oldHandler.indexOf(")",validatorIndex);
  59.  
  60.     //if parenthesis not found, abort
  61.     if (endIndex<0) return;
  62.  
  63.     // create a String for the name of the validator function,
  64.     // and store it as a new property of the Form
  65.     document.forms[i].oldValidator = new String(oldHandler.slice(startIndex,endIndex+1));
  66.  
  67.     /* oldValidator is something like this:
  68.     * "FrontPage_Form1_Validator(this);"
  69.  
  70.     */
  71.    }
  72.  
  73.    else {  //Form did not have an onSubmit handler previously
  74.         document.forms[i].oldValidator = new String("true;");
  75.     }
  76.  
  77.    //substitute our own onSubmit handler for the one FrontPage created
  78.    document.forms[i].onsubmit = enhancedValidator;
  79.  
  80.   } //end for
  81.  
  82. } //end hijackValidator()
  83.  
  84. function enhancedValidator() {
  85.  
  86.  /* This is our new validator function.
  87.  * It first calls the FrontPage validator for the Form.
  88.  * If that returns TRUE, it then checks whether the Form
  89.  * has already been submitted.
  90.  * If it has been, we do not submit it again.
  91.  */
  92.  
  93.  if (eval(this.oldValidator.valueOf())) { // is FrontPage validation successful?
  94.  
  95.   if (this.notSubmittedYet) {  //did user click Submit already?
  96.    this.notSubmittedYet = false;
  97.    return true; // submit form
  98.   }
  99.  
  100.   else { // form already submitted; complain to user
  101.    alert("You have already submitted the form.  Please be patient. \nThe Internet has had a busy day and is a little tired, but as soon as it catches its breath, it will deliver your confirmation message.");
  102.    return false;  // don't submit form
  103.   }
  104.  
  105.  }
  106.  
  107.  else { // FrontPage validator found error
  108.   return false;  // don't submit form
  109.  }
  110.  
  111. } // end enhancedValidator()
  112. //  End -->
  113. </script>
  114.  
  115.  
  116. <!-- STEP TWO: Insert the onLoad event handler into your BODY tag  -->
  117.  
  118. <BODY onLoad="hijackValidator()">
  119.  
  120. ->
  121.  
  122. <!-- END OF SCRIPT -->
  123. <!/SCRIPT>
  124.  
  125. <!PREVIEW>
  126. <!-- START OF SCRIPT -->
  127.  
  128. <!-- HOW TO INSTALL SUBMIT ONCE FOR FRONTPAGE:
  129.  
  130.   1.  Copy code into the HEAD section of document
  131.   2.  Add the onLoad event handler into the BODY tag  -->
  132.  
  133. <!-- STEP ONE: Add code into HEAD section of document  -->
  134.  
  135. <HEAD>
  136.  
  137. <SCRIPT LANGUAGE="JavaScript">
  138.  
  139.  
  140. <!-- Begin
  141. function hijackValidator() {
  142.   // loop through all the Forms in the document
  143.   for (i=0; i<document.forms.length; i++) {
  144.  
  145. /* create a new property of the Form that tracks whether the Form has been submitted*/
  146.  
  147.    document.forms[i].notSubmittedYet = true;
  148.    if (document.forms[i].onsubmit) {
  149.     var oldHandler = new String(document.forms[i].onsubmit)
  150.  
  151. /*  oldHandler will be something like this, depending on the browser in use,
  152. *   and the name of the Form:
  153. *
  154. *   "function anonymous() { return FrontPage_Form1_Validator(this); }"
  155. *
  156. *   We need to extract just the "FrontPage_Form1_Validator(this)" part
  157. */
  158.  
  159.     //find "Validator"
  160.     var validatorIndex = oldHandler.indexOf("Validator");
  161.  
  162.     //if "Validator" not found, then abort
  163.     if (validatorIndex<0) return;
  164.  
  165.     //find space before name of validator function
  166.     var startIndex = oldHandler.lastIndexOf(" ",validatorIndex)
  167.  
  168.     // if space not found, abort
  169.     if (startIndex<0) return;
  170.  
  171.     // find final parenthesis
  172.     var endIndex = oldHandler.indexOf(")",validatorIndex);
  173.  
  174.     //if parenthesis not found, abort
  175.     if (endIndex<0) return;
  176.  
  177.     // create a String for the name of the validator function,
  178.     // and store it as a new property of the Form
  179.     document.forms[i].oldValidator = new String(oldHandler.slice(startIndex,endIndex+1));
  180.  
  181.     /* oldValidator is something like this:
  182.     * "FrontPage_Form1_Validator(this);"
  183.  
  184.     */
  185.    }
  186.  
  187.    else {  //Form did not have an onSubmit handler previously
  188.         document.forms[i].oldValidator = new String("true;");
  189.     }
  190.  
  191.    //substitute our own onSubmit handler for the one FrontPage created
  192.    document.forms[i].onsubmit = enhancedValidator;
  193.  
  194.   } //end for
  195.  
  196. } //end hijackValidator()
  197.  
  198. function enhancedValidator() {
  199.  
  200.  /* This is our new validator function.
  201.  * It first calls the FrontPage validator for the Form.
  202.  * If that returns TRUE, it then checks whether the Form
  203.  * has already been submitted.
  204.  * If it has been, we do not submit it again.
  205.  */
  206.  
  207.  if (eval(this.oldValidator.valueOf())) { // is FrontPage validation successful?
  208.  
  209.   if (this.notSubmittedYet) {  //did user click Submit already?
  210.    this.notSubmittedYet = false;
  211.    return true; // submit form
  212.   }
  213.  
  214.   else { // form already submitted; complain to user
  215.    alert("You have already submitted the form.  Please be patient. \nThe Internet has had a busy day and is a little tired, but as soon as it catches its breath, it will deliver your confirmation message.");
  216.    return false;  // don't submit form
  217.   }
  218.  
  219.  }
  220.  
  221.  else { // FrontPage validator found error
  222.   return false;  // don't submit form
  223.  }
  224.  
  225. } // end enhancedValidator()
  226. //  End -->
  227. </script>
  228.  
  229.  
  230. <!-- STEP TWO: Insert the onLoad event handler into your BODY tag  -->
  231.  
  232. <BODY onLoad="hijackValidator()">
  233.  
  234. ->
  235.  
  236.  
  237. <!-- END OF SCRIPT -->
  238. <!/PREVIEW>
  239.  
  240. <!RELATED>NONE<!/RELATED>
  241.